package com.example.shop.common.executor.implement;

import com.example.shop.common.executor.interfaces.ExecutorAsyncService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

import java.util.Random;

/**
 * @author haocj
 * 异步线程任务实现类
 */
@Service
public class ExecutorAsyncServiceImpl implements ExecutorAsyncService {

    private static final Logger logger = LoggerFactory.getLogger(ExecutorAsyncServiceImpl.class);

    @Autowired
    private RedisTemplate redisTemplate;

    @Override
    @Async("asyncServiceExecutor")
    public void executeAsync() {
        logger.info("start executeAsync");
        Random r = new Random();
        int i = r.nextInt(10000) + 2000;
        System.out.println("异步线程开始要做的事情");
        try {
            Thread.sleep(i);
        } catch (Exception e) {
            e.printStackTrace();
        }
        System.out.println("执行了" + i + "的时间");

        logger.info("end executeAsync");
    }
    
}
